#! /usr/bin/python
# -*- coding: cp1250 -*-

import re, string, glob, sys
import pepe.p_txt.bigtxt as bt
import win32api

def main():
    ''' Utility for extraction of ET Deloitte rates from 
            C:\AFT\pmfs\ETQR\EmployeesStandardRates.txt
            which in turn was generated via ETQR utility
    '''
    data = {}
    frn = [   'Balintova, Maria'        , 'Bican, Daniel'       , 'Bohac, Jaromir'
            , 'Presovsky, Viktor'       , 'Palaci, Flavio'      , 'Fatura, Karel'
            , 'Zielke, Daniel'
            , 'Zemanek, Jan'            , 'Augusta, Jindrich'
            , 'Zvolsky, Pavel'          , 'Sadlik, Tomas'       , 'Hladka, Pavla'
            , 'Strimbeanu, Alexandru'
            , 'Rosen, Zachary'          , 'Sandrej, Igor'
            
            , 'Balatka, Jan'            , 'Travnicek, Tomas'
            , 'Skala, Zbynek'
            ]
    # , 'Sagat, Michal', 'Holodnak, Maros'
    # , 'York, Steven'
    #for line in bt.lines(sys.argv[1]):
    for line in bt.lines("""C:\AFT\pmfs\ETQR\EmployeesStandardRates.txt"""):
        line = re.sub('\n', '', line)
        if line == '':
            pass
        else:
            cols = string.split(line,'\t')
            if cols[0] in frn: data[cols[0]] = cols[:4]
    fo = open("""deloitte-rates-dttr.log""",'w')
    fo.write("""|Surname, Name|Position|Currency|StandardRate|InterOffRate|\n""")
    for k in sorted(data.keys()):
        res = data[k]
        fo.write( "|%s|%s|\n" % (string.join(res, '|'), round((float(res[-1])/5*56/100))*5) )
        # is calculated here ... """=ROUND($C25/5*G$6/100;0)*5"""
    fo.write("""\n\n/%\nSurname, Name\tPosition\tCurrency\tStandardRate\tInterOffRate\n""")
    for k in sorted(data.keys()):
        res = data[k]
        fo.write( "%s\t%s\n" % (string.join(res, '\t'), round((float(res[-1])/5*56/100))*5) )
        # is calculated here ... """=ROUND($C25/5*G$6/100;0)*5"""
    fo.write("""%/""")
    fo.close()
    win32api.WinExec("""notepad C:\AFT\pepe\p_utils\dttr.pyw""")
    win32api.WinExec("""notepad deloitte-rates-dttr.log""")

if __name__ == "__main__":
    ''' '''
    main()
